<template>
  <j-modal
    :title="title"
    :width="width"
    :visible="visible"
    :confirmLoading="confirmLoading"
    switchFullscreen
    @ok="handleOk"
    @cancel="handleCancel"
    cancelText="关闭">
    <a-spin :spinning="confirmLoading">
      <a-form-model ref="form" :model="model" :rules="validatorRules">
        <a-row>
<!--          <a-col :span="24">
            <a-form-model-item label="任务名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="taskName">
              <a-input v-model="model.taskName"placeholder="请输入任务名称" ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="订单编号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="orderNo">
              <a-input v-model="model.orderNo"placeholder="请输入订单编号" ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="订单ID" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="orderId">
              <a-input v-model="model.orderId"placeholder="请输入订单ID" ></a-input>
            </a-form-model-item>
          </a-col>-->
          <a-col :span="24">
            <a-form-model-item label="收款金额" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="paymentAmount">
              <a-input-number v-model="model.paymentAmount"placeholder="请输入收款金额" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="收款时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="paymentTime">
              <j-date placeholder="请选择收款时间" v-model="model.paymentTime" style="width: 100%" :show-time="true" date-format="YYYY-MM-DD HH:mm:ss" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="收款方式" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="paymentMethod">
              <j-dict-select-tag type="list" v-model="model.paymentMethod" dictCode="payment_method" placeholder="请选择收款方式" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="付款方名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="payerName">
              <a-input v-model="model.payerName"placeholder="请输入付款方名称" ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="付款方账号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="payerAccount">
              <a-input v-model="model.payerAccount"placeholder="请输入付款方账号" ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="收款方账号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="receiverAccount">
              <a-input v-model="model.receiverAccount"placeholder="请输入收款方账号" ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="交易流水号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="transactionNo">
              <a-input v-model="model.transactionNo"placeholder="请输入交易流水号" ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="是否开票" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="invoiceIssued">
              <j-dict-select-tag type="radio" v-model="model.invoiceIssued" dictCode="invoice_issued" placeholder="请选择是否开票" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="发票号码" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="invoiceNo">
              <a-input v-model="model.invoiceNo"placeholder="请输入发票号码" ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="开票日期" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="invoiceDate">
              <j-date placeholder="请选择开票日期" v-model="model.invoiceDate" style="width: 100%" :show-time="true" date-format="YYYY-MM-DD HH:mm:ss" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="收款备注" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="paymentRemarks">
              <a-textarea v-model="model.paymentRemarks" rows="4" placeholder="请输入收款备注" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="确认人" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="confirmedBy">
              <j-select-user-by-dep v-model="model.confirmedBy"/>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="确认时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="confirmedTime">
              <j-date placeholder="请选择确认时间" v-model="model.confirmedTime" style="width: 100%" :show-time="true" date-format="YYYY-MM-DD HH:mm:ss" />
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </a-spin>
  </j-modal>
</template>

<script>

  import { httpAction } from '@/api/manage'
  import { validateDuplicateValue } from '@/utils/util'

  export default {
    name: "YjOrderPaymentModal",
    components: {
    },
    props:{
      mainId:{
        type:String,
        required:false,
        default:''
      }
    },
    data () {
      return {
        title:"操作",
        width:800,
        visible: false,
        model:{
        },
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },

        confirmLoading: false,
        validatorRules: {
           taskName: [
              { required: true, message: '请输入任务名称!'},
           ],
           orderNo: [
              { required: true, message: '请输入订单编号!'},
           ],
           paymentAmount: [
              { required: true, message: '请输入收款金额!'},
           ],
           paymentTime: [
              { required: true, message: '请输入收款时间!'},
           ],
           paymentMethod: [
              { required: true, message: '请输入收款方式!'},
           ],
           // payerName: [
           //    { required: true, message: '请输入付款方名称!'},
           // ],
           // payerAccount: [
           //    { required: true, message: '请输入付款方账号!'},
           // ],
           // receiverAccount: [
           //    { required: true, message: '请输入收款方账号!'},
           // ],
           invoiceIssued: [
              { required: true, message: '请输入是否开票!'},
           ],
           confirmedBy: [
              { required: true, message: '请输入确认人!'},
           ],
        },
        url: {
          add: "/erp/yjOrderPaymentList/addYjOrderPayment",
          edit: "/erp/yjOrderPaymentList/editYjOrderPayment",
        }

      }
    },
    created () {
    //备份model原始值
      this.modelDefault = JSON.parse(JSON.stringify(this.model));
    },
    methods: {
      add () {
        this.edit(this.modelDefault);
      },
      edit (record) {
        this.model = Object.assign({}, record);
        this.visible = true;
      },
      close () {
        this.$emit('close');
        this.visible = false;
        this.$refs.form.clearValidate();
      },
      handleOk () {
        const that = this;
        // 触发表单验证
        this.$refs.form.validate(valid => {
          if (valid) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            this.model['orderId'] = this.mainId
            httpAction(httpurl,this.model,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
              that.close();
            })
          }else{
             return false
          }
        })
      },
      handleCancel () {
        this.close()
      },


    }
  }
</script>
